import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * 注意:子菜单只在route children.length>=1时出现
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为true，条目将不会显示在侧栏中(默认为false)
 * alwaysShow: true              如果设置为true，将始终显示根菜单
 *                                如果不始终设置Show，当item有多个子路由时，
 *                                它将变成嵌套模式，否则不会显示根菜单
 * redirect: noRedirect            如果设置了no Redirect将不会在面包屑中重定向
 * name:'router-name'            <keep alive>(必须设置!!)
 * meta : {
    roles: ['admin','editor']    控制页面角色(可以设置多个角色)
    title: 'title'               名称显示在侧边栏和breadcrumb(推荐设置)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false           图标显示在侧边栏
    activeMenu: '/example/list'  如果设置路径，侧边栏将突出显示您设置的路径
  }
 */

/**
  constant路由一个没有权限要求的基本页面，所有角色都可以访问
 */

export const constantRoutes1 = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: false,
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: false
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

 
  {
    path: '/form',
    component: Layout,
    
    children: [
      {
       
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: '表单', icon: 'form' }
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '嵌套',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' }
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' }
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' }
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' }
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: 'menu2' }
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: '外部链接', icon: 'link' }
      }
    ]
  },

  // 404页面必须放在最后!!
  { path: '*', redirect: '/404', hidden: true }
]
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: false,
  },

 

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

 
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: false
  },

  // // 404页面必须放在最后!!
  // { path: '*', redirect: '/404', hidden: true }
]
//动态需要根据权限加载的路由表 
export const asyncRouterMap =[
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: false,
    name: 'login',
  },
  
 

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

 
 

  // 订单详情
  {
    path: '/orders',
    component: Layout,
    name: "订单",
    meta: { title: '订单', icon: 'order' },
    hidden: true,
    children: [{

      path: '/orders/orderDetail',
      name: '订单详情',
      meta: { title: '订单详情'},
      hidden: true,
      component: () => import('@/views/orders/order_Detail'),
    }]
  },
  //修改菜单
  {
    path: '/access',
    component: Layout,
    name: "权限",
    meta: { title: '权限', icon: 'order' },
    hidden: true,
    children: [{

      path: '/access/menuDetail',
      name: '菜单修改',
      meta: { title: '菜单修改'},
      hidden: false,
      component: () => import('@/views/access/menu_set/modify_menu.vue'),
    }]
  },
  {
    path: '/editor',
    component: () => import('@/views/dashboard/editor/index'),
    hidden: false
  },
 
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: false
  },
  {
    path:'/403',
    component: () => import('@/views/403'),
    hidden: false
  }
  // // 404页面必须放在最后!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // Mode: 'history',//需要服务支持
  scrollBehavior: () => ({ y: 0 }),
  routes: asyncRouterMap
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  console.log(constantRoutes)
  router.options.routes = constantRoutes
  // router.matcher = newRouter.matcher // reset router
}

export default router 
